// App Root
var appPath = getAppPath();

// Dialog ID
var dialog_id = "#configDlg";

// Form ID
var form_id = "#configForm";

// 图片服务器地址
var images1Path = "http://www.hs568.cn";

/**
 * jQuery加载事件
 */
$(function(){
	refreshForm();
	initCommonUpload();
});

/**
 * 刷新Form
 */
function refreshForm() {
	$.loading(true);
	$.ajax({
		url:appPath+'/system/sysConfig_one.do',
		type:"post",
		success:function(data){
			$.loading(false);
			$(form_id).form('clear');
			$(form_id).form('load',data);
			
			if (data.logo != undefined && data.logo != null) {
				$('#uploadImg').attr("src",images1Path + data.logo);
			}
			else {
				$("#uploadImg").hide();
			}
		},
		error:function(XMLHttpRequest, textStatus, errorThrown){
			$.loading(false);
			$.messager.alert('提示信息','抱歉，操作未能完成，'+textStatus,'error');
		}
	});
}

/**
 * 提交数据（包括增加，修改）
 */
function doPostData(){
	$("#webTitle").val($.trim($("#webTitle").val()));
	
	if(!$(form_id).form('validate')){
		return ;
	}
	
	var subData = $(form_id);  
    var config = subData.serialize();    
	
    var type = "saveOrUpdate";
    if (type == "save") {
    	ajaxPostData(type, config);
    } else {
    	ajaxPostData(type, config);
    }
}

function ajaxPostData(type, config) {
	$.loading(true);
	$.ajax({
		url:appPath+'/system/sysConfig_saveOrUpdate.do',
		type:"post",
		data:config,
		success:function(data){
			$.loading(false);
			refreshForm();
		},
		error:function(XMLHttpRequest, textStatus, errorThrown){
			$.loading(false);
			$.messager.alert('提示信息','抱歉，'+typeStr+'未能完成，'+textStatus,'error');
		}
	});
}

//**************************************文件上传相关的的*******start***********************************************
/**
 * 初始化上传控件
 */
function initCommonUpload() {
	//$("#divStatus").hide();
	//$("#uploadImg").css("display", "none");
	var attach = new Object();
	attach.attachNo = generateNo("logo");
	attach.attachNotes = "";
	attach.attachType = "pic";
	attach.picType = "";
	attach.splitKey = "";//定义图片切割大小
	attach.fileType = "*.jpg;*.gif;*.png;";
	attach.fileCount = "singleSelect"; //singleSelect 表示一次只能选择一个文件上传
	initUpload('logo_','logo',attach);
}

/**
 * 上传成功后触发的事件
 */
function commonSuccessReturn(attachList){
	var len = attachList.length;
	//console.info("=======len:"+len);
	for(var i=0;i<attachList.length;i++){
		//console.info("=========start  print================");
		//console.info("id:"+attachList[i].id);
		//console.info("name:"+attachList[i].attachRealName);
		//console.info("picType:"+attachList[i].picType);
		if(attachList[i].picType==""){
			//$('#picId').val();
			//$('#attachRealName').val();
			$('#picId').val(attachList[i].attachId);
			$('#logo').val(attachList[i].attachRealName);
			var imgPath=images1Path+attachList[i].attachPath;
			$("#uploadImg").css("display", "block");
			$('#uploadImg').attr("src",imgPath);
		}
	}
}
//**************************************文件上传相关的的*******end***********************************************

